package com.example.bms.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.bms.entity.FillQuestion;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import java.util.List;


/**
 * @apiNote 实现对填空题的增加和查询
 * @author
 * @email 2918185121@qq.com
 * @since 1.0.0
 */
//填空题
@Mapper
public interface FillQuestionMapper {


    /**
     * @apiNote 查询中等难度系数的填空题
     * @author
     * @email 2918185121@qq.com
     * @return List<FillQuestion>
     * @since 1.0.0
     */
    @Select("select * from fill_question where questionId in (select questionId from paper_manage where questionType = 2 and paperId = #{paperId})")
    List<FillQuestion> findByIdAndType(Integer paperId);


    /**
     * @apiNote 查询所有填空题
     * @param page 分页
     * @author
     * @email 2918185121@qq.com
     * @return 以FillQuestion为数据类型的IPage对象集合
     * @since 1.0.0
     */
    @Select("select * from fill_question")
    IPage<FillQuestion> findAll(Page page);


    /**
     * @apiNote 查询最后一条questionId
     * - questionId 问题id
     * @author
     * @email 2918185121@qq.com
     * @return FillQuestion
     * @since 1.0.0
     */
    @Select("select questionId from fill_question order by questionId desc limit 1")
    FillQuestion findOnlyQuestionId();


    /**
     * @apiNote 增加一道填空题
     * @author
     * @param fillQuestion 填空题对象
     * - questionId 问题编号
     * - answer 答案
     * - analysis 分析
     * - level 难度
     * - examDate 考试发布时间
     * - section 模块区分
     * @email 2918185121@qq.com
     * @return int，插入成功返回1，插入失败返回0
     * @since 1.0.0
     */
    @Options(useGeneratedKeys = true,keyProperty ="questionId" )
    @Insert("insert into fill_question(subject,question,answer,analysis,level,section) values " +
            "(#{subject,},#{question},#{answer},#{analysis},#{level},#{section})")
    int add(FillQuestion fillQuestion);


    /**
     * @apiNote 查询最后一条questionId
     * @author
     * @param subject 科目
     * @param pageNo 页码
     * - subject 科目
     * - pageNo 页码
     * @email 2918185121@qq.com
     * @return List<Integer>
     * @since 1.0.0
     */
    @Select("select questionId from fill_question where subject = #{subject} order by rand() desc limit #{pageNo}")
    List<Integer> findBySubject(String subject,Integer pageNo);
}
